package airplane.obj;

import airplane.utils.GameUtils;
import airplane.war.GameWin;

import java.awt.*;

public class EnemyObj extends GameObj{

    public EnemyObj(Image imag, int x, int y, int width, int height, int speed, GameWin gameWin) {
        super(imag, x, y, width, height, speed, gameWin);
    }

    @Override
    public void paintSelf(Graphics graphics) {
        super.paintSelf(graphics);
        y += speed;

        if (y > 700) {
            GameUtils.enemyObjList.remove(this);
        }
        // 敌我飞机碰撞检测
        if (this.getRec().intersects(this.gameWin.planeObj.getRec())) {
            GameWin.state = 3;
            gameWin.repaint = 0;
        }

        // 子弹碰撞检测
        for (ShellObj shellObj : GameUtils.shellObjList) {
            if (this.getRec().intersects(shellObj.getRec())) { // 发生碰撞
                this.x = -200;
                this.y = 200;
                shellObj.setX(-100);
                shellObj.setY(100);
                GameUtils.enemyObjList.add(this);
                GameUtils.removeObjList.add(shellObj);
                GameWin.score++;
            }
        }
    }
}
